$(function(){
	var url = common.url();
	var jk = common.Interface('detail')[0];
	if(common.search().id){
		var proid = common.search().id;
	}else{
		alert('详情id有误，请重新点击链接')
	}
	
	// 判断是否登陆
	var onloginoff = false; 
	var loginurl= common.Interface('onlogin')[0]
	$.ajax({
		url : loginurl,
		type: "POST",
		error: function(request) {
			//console.log(request)
		},
		dataType:"json",
		success: function(data) {
			onloginoff = data.data;
		}
	})
	// 详情
	var url = jk + proid ;
	$.ajax({
		url : url,
		type: "POST",
		async: true,
		error: function(request) {
			//console.log(request)
		},
		dataType:"json",
		success: function(data) {
			if(data.ret){
				var json =data.data;
				if(json.privilegeLevel == 'VISITOR'){
				}else if(json.privilegeLevel == 'NORM'){
					if(onloginoff == 'VISITOR' || !onloginoff ){
						$('.header-box').css({'display':'block'});
						$('.boxbg').css({'display':'block'});
						$('.tanbox').css({'display':'none'});
						$('.login-box').css({'display':'block'});
						$('.showboxtitle').html('登陆');
						$('.baocuo').html('此文章需要登录才能查看，请登陆...');
						return false;
					}
				}else if(json.privilegeLevel == 'VIP'){
					if(onloginoff != 'VIP' || !onloginoff){
						$('.header-box').css({'display':'block'});
						$('.boxbg').css({'display':'block'});
						$('.tanbox').css({'display':'none'});
						$('.login-box').css({'display':'block'});
						$('.showboxtitle').html('登陆');
						$('.baocuo').html('此文章需要VIP账户才能查看')
						return false;
					}
				}
				$('.detail-title').html(json.title);
				$('.where span').html(json.source);
				$('.who span').html(json.author);
				$('.time').html(json.pubdate.split(' ')[0]);
				$('.see-times span').html(json.readCount);
				$('.detail-box').html(json.content);
				if(json.previousId !=0){
					$('.pages-prev').attr({'previd':json.previousId});
					$('.pages-prev').bind('click',function(){
						window.location.href ='http://'+ window.location.host +'/detail.htm?id='+$(this).attr('previd')
					})
				}else{
					$('.pages-prev').css({'cursor':'not-allowed','color':'#ccc'})
				}
				if(json.nextId !=0){
					$('.pages-next').attr({'nextid':json.nextId});
					$('.pages-next').bind('click',function(){
						window.location.href = 'http://'+ window.location.host +'/detail.htm?id='+$(this).attr('nextid')
					})
				}else{
					$('.pages-next').css({'cursor':'not-allowed','color':'#ccc'})
				}
				$('table').attr({'cellspacing':0}).css({'border':'1px solid #000'});
				
			}
		}
	})
	
})
